#include "../include/gudb.h"
#include "../src/parser/sql_parser.h"
#include <stdio.h>
#include <stdlib.h>

int main() {
    printf("Testing CREATE INDEX parsing...\n");
    
    const char* sql = "CREATE INDEX idx_test ON users (id)";
    
    // Create parser
    parser_t* parser = parser_create(sql);
    if (!parser) {
        printf("Failed to create parser\n");
        return 1;
    }
    
    // Try to parse the statement
    statement_t* stmt = parser_parse_statement(parser);
    if (!stmt) {
        printf("Failed to parse statement\n");
        printf("Parser error: %s\n", parser_get_error(parser));
        parser_destroy(parser);
        return 1;
    }
    
    printf("Successfully parsed statement\n");
    printf("Statement type: %d\n", stmt->type);
    
    if (stmt->type == STMT_CREATE_INDEX) {
        printf("Parsed as CREATE INDEX statement\n");
        printf("Index name: %s\n", stmt->data.create_index.index_name ? stmt->data.create_index.index_name : "NULL");
        printf("Table name: %s\n", stmt->data.create_index.table_name ? stmt->data.create_index.table_name : "NULL");
        printf("Column count: %d\n", stmt->data.create_index.column_count);
        printf("Is unique: %s\n", stmt->data.create_index.unique ? "true" : "false");
    } else {
        printf("Parsed as different statement type: %d\n", stmt->type);
    }
    
    // Clean up
    statement_destroy(stmt);
    parser_destroy(parser);
    
    return 0;
}